package cn.kilo.domain.service.infterface.impl;

import cn.kilo.domain.model.order.entity.OrderEntity;
import cn.kilo.domain.model.order.entity.StaffEntity;
import cn.kilo.domain.model.order.vo.OrderStatusVO;
import cn.kilo.domain.service.infterface.IRoleJob;
import cn.kilo.domain.service.order.IStaffStrategyChain;
import cn.kilo.domain.service.order.factory.DefaultFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author kilok
 */
@Slf4j
@Service
public class RoleJob implements IRoleJob {

    private DefaultFactory defaultFactory;

    public RoleJob(DefaultFactory defaultFactory) {
        this.defaultFactory = defaultFactory;
    }

    /**
     * 使用工厂分配对应实现，实体里必须要有对应的status字段作为标识
     *
     * @param orderEntity
     * @return
     */
    @Override
    public List<OrderStatusVO> performJob(OrderEntity orderEntity) {
        log.info("status:{}",orderEntity.getStatus());
        IStaffStrategyChain chain=defaultFactory.getChain(orderEntity.getStatus());
        return chain.doJob(orderEntity);
    }

    @Override
    public Map<String, Integer> getLeftStaff(OrderEntity order) {
        IStaffStrategyChain chain=defaultFactory.getChain(order.getRole());
        return chain.getLeftStaff(order);
    }

    @Override
    public boolean beStaff(StaffEntity staffEntity) {
        IStaffStrategyChain chain=defaultFactory.getChain(staffEntity.getRole());
        return chain.beStaff(staffEntity);
    }
}
